package com.liang.controller;



import com.liang.empty.Result;
import com.liang.mapper.MenuDAO;
import com.liang.pojo.Menu;
import com.liang.security.MySecurity;
import com.liang.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

;

/**
 *@作者:lsk
 *Controller接口
 *@Date:2023/07/13
*/
@RestController
@RequestMapping("/MenuURL")
public class MenuController {


	@Autowired
	private MenuService menuservice;

	@Resource
	private MenuDAO menuDAO;


	/**
	根据MenuId查询
	*/
	@MySecurity(methodx = "1")
	@GetMapping("/selectByMenuId/{menuId}")
	public Result selectByMenuId(@PathVariable(value = "menuId") Integer menuId){
		return Result.buildSuccess(menuservice.selectByMenuId(menuId));
	}


	/**
	根据MenuId更新
	*/
	@MySecurity(methodx = "3")
	@PostMapping("/updateByMenuId")
	public Result updateByMenuId(@RequestBody Menu demo){
		return Result.buildSuccess(menuservice.updateByMenuId( demo));
	}



	/**
	根据MenuId删除
	*/
	@MySecurity(methodx = "4")
	@GetMapping("/deleteByMenuId/{menuId}")
	public Result deleteByMenuId(@PathVariable(value = "menuId") Integer menuId){
		return Result.buildSuccess(menuservice.deleteByMenuId(menuId));
	}



	/**
	 insert:(插入)
	*/
	@MySecurity(methodx = "2")
	@PostMapping("/insert")
	public Result insert(@RequestBody Menu demo){
		Result.buildSuccess(menuservice.insert(demo));
		return Result.buildSuccess(demo);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
//	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Menu demo){
		return Result.buildSuccess(menuservice.insertOrUpdate(demo));
	}



	/**
	 insertBath:(批量插入)
	*/
//	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Menu> list){
		return Result.buildSuccess(menuservice.insertBatch(list));
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
//	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Menu> list){
		return Result.buildSuccess(menuservice.insertOrUpdateBatch(list));
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	@MySecurity(methodx = "1")
	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",menuservice.selectCount(param));
		}
		map.put("data",menuservice.selectList(param));
		return Result.buildMessage(map,"查询菜单完成",200);
	}





	/**
	 selectCount:(根据集合查询数量)
	*/
//	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildSuccess(menuservice.selectCount(param));
	}



}